	var worldcitylist = new relatedSelection(worldcity,{value:"?>1>11>1"});

	var listSchool = function(){
			var schoolLevel = document.getElementById("schoollevelset").value;
			var country = $("select[name=countrycode] option:selected").text();
			var province = $("select[name=provincecode] option:selected").text();
			var indexLetter = $.trim($("#indexletter").find("a.cur").text().toUpperCase());
			if(indexLetter == "全部"){indexLetter="";}
			$.ajax({
				type:"GET",
				url:"index.php?m=a_schoollist",
				data:"type="+schoolLevel+"&key="+encodeURI([country,province].join("_"))+"&letter="+(indexLetter?indexLetter:""),
				dataType:"json",
				success : function( result ){
					var schoollistwrapper = $("#schoollistwrapper");
					if(result.code == 0){
						var data = $(result.data);
						data.find("li > a").click(function(){
							var _this = $(this);
							$("#shoolinput").val(_this.attr("title"));
							$("#schoolid").val(_this.attr("data-schoolid"));
							schoolBox.remove();
						});
						schoollistwrapper.html("").append(data);
					}else{
						var data=$("<div class=\"noschool\">"+result.msg+"</div>");
						schoollistwrapper.html("").append(data);
					}
				},
				error : function(){
					var schoollistwrapper = $("#schoollistwrapper");
					var data=$("<div class=\"noschool\">获取学校列表失败，请稍后重试</div>");
					schoollistwrapper.html("").append(data);
				}
			});
		};	
	var listDepartment = function(){
			var schoolid = $("#schoolid").val();
			$.ajax({
				type:"GET",
				url:"index.php?m=a_departmentlist",
				data:"schoolid="+schoolid,
				dataType:"json",
				success:function(result){
					var departmentwrapper = $("#departmentwrapper");
					if(result.code == 0){
						var data = $(result.data);
						data.find("li > a").click(function(){
							var _this = $(this);
							$("#departmentinput").val(_this.attr("title"));
							$("#departmentid").val(_this.attr("data-departmentid"));
							departmentBox.remove();
						});
						departmentwrapper.html("").append(data);
					}else{
						var data=$("<div class=\"nodepartment\">"+result.msg+"</div>");
						schoollistwrapper.html("").append(data);
					}
				},
				error:function(){
					var departmentwrapper = $("#departmentwrapper");
					var data=$("<div class=\"nodepartment\">获取院系列表失败，请稍后重试</div>");
					departmentwrapper.html("").append(data);
				}
			});
		}
	var worldcityCtrl = function(countryChange,provinceChange){
		var rs = document.getElementById("relateSelectionWrapper");
		var rsselect = rs.getElementsByTagName("select");
		rsselect[0].name = "countrycode";
		rsselect[1].name = "provincecode";
		rsselect[2].name = "citycode";
		rsselect[2].style.display="none";//
		for(var i=0;i<rsselect.length;i++){
			var sl = rsselect[i];
			if(sl.length==1){//为?即空
				sl.style.display="none";
			}
		}
		rsselect[0].onchange = function(){
			rsselect[1].options.length = 0;
			rsselect[2].options.length = 0;
			worldcitylist.sel=["?",this.options[this.selectedIndex].text].join(">");
			if(worldcitylist.getOptions().length==29){//省份为空,直接控制城市
				rsselect[1].style.display="none";			
				rsselect[2].style.display="";
				worldcitylist.sel=["?",this.options[this.selectedIndex].text,"?"].join(">");
				if(worldcitylist.getOptions().length==29){//城市为空
					rsselect[2].style.display="none";
				}else{
					worldcitylist.addOptionObjects(rsselect[2]);
				}
			}else{
				worldcitylist.addOptionObjects(rsselect[1]);
				rsselect[1].style.display="";
				rsselect[2].style.display="none";
			}
			
			if(countryChange){
				countryChange();
			}
		};
		
		if(provinceChange){
			rsselect[1].onchange = function(){
				provinceChange();
			};
		}
	}
		
	window.onload = function(){
		var schoolType = document.getElementById("schoollevelset");
		var deparment = document.getElementById("departmentset");
		var deparmentinput = document.getElementById("departmentinput");
		var schoolInput = document.getElementById("shoolinput");
		var highEdu = parseInt(schoolType.value,10) >= 4;
		
		schoolType.onchange = function(){
			deparmentinput.value="";
			schoolInput.value="";
			var val = parseInt(schoolType.value,10);
			if(val<4){
				deparment.style.display="none";
			}else{
				deparment.style.display="";
			}
		};
		
		$("#showschoolselect").click(function(){
			var regionList = worldcitylist.getHTML();
			var mainContentHTML = "<div id=\"dialogmainwrapper\"><div id=\"dialogmain\"><div id=\"regions\"></div><div id=\"indexletter\"></div><iframe class=\"cover_select\" frameBorder=\"0\" style=\"height:250px;\"></iframe><div id=\"schoollistwrapper\"></div></div></div>"
			var mainContentObj = $(mainContentHTML);
			
			mainContentObj.find("#regions").html("<div class=\"toleft\">学校所在地:</div>"+regionList);
			mainContentObj.find("#indexletter").html("<a href=\"#\" class=\"all cur\">全部</a><a href=\"#\">A</a><a href=\"#\">B</a><a href=\"#\">C</a><a href=\"#\">D</a><a href=\"#\">E</a><a href=\"#\">F</a><a href=\"#\">G</a><a href=\"#\">H</a><a href=\"#\">I</a><a href=\"#\">J</a><a href=\"#\">K</a><a href=\"#\">L</a><a href=\"#\">M</a><a href=\"#\">N</a><a href=\"#\">O</a><a href=\"#\">P</a><a href=\"#\">Q</a><a href=\"#\">R</a><a href=\"#\">S</a><a href=\"#\">T</a><a href=\"#\">U</a><a href=\"#\">V</a><a href=\"#\">W</a><a href=\"#\">X</a><a href=\"#\">Y</a><a href=\"#\">Z</a>");
			var indexletters = mainContentObj.find("#indexletter").find("a");
			
			indexletters.click(function(){//按字母查询
					var _this = $(this);
					indexletters.removeClass("cur");
					_this.addClass("cur");
					listSchool();
			});			
			var schoolBox = new dialog("选择学校",630,343,mainContentObj);
			schoolBox.show();
			window.schoolBox = schoolBox;
			worldcityCtrl(listSchool,listSchool);//当前地区拉全部学校列表
			listSchool();
		});

		$("#showdepartmentselect").click(function(){
			if(!!!$("#schoolid").val()){
				$.richAlertBox("请先选择学校","error").show();
				return;
			}
			var mainContentHTML="<div id=\"dialogmainwrapper\"><div id=\"dialogmain\"><iframe class=\"cover_select\" frameBorder=\"0\" style=\"height:200px;\"></iframe><div id=\"departmentwrapper\"></div></div></div>";
			var mainContentObj = $(mainContentHTML);
			var departmentBox = new dialog("选择院系",630,212,mainContentObj);
			departmentBox.show();
			window.departmentBox = departmentBox;
			listDepartment();
		});
	};

	function saveform(){
		$("#setForm").submit();
	}